home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4364 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: hptemp1.cc.umr.edu!phaley
  2. From: phaley@saucer.cc.umr.edu (Paul Haley)
  3. Newsgroups: comp.lang.c
  4. Subject: Need help on program
  5. Date: 4 Feb 1996 00:41:01 GMT
  6. Organization: UMR Missouri's Technological University
  7. Message-ID: <4f0vat$j8j@hptemp1.cc.umr.edu>
  8. NNTP-Posting-Host: saucer.cc.umr.edu
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11.     Hello.  I'm trying to write a program which will count the total 
  12. amount of a "poker" jackpot.  I read the input into an array, then read 
  13. the array values in, and take appropriate action. 
  14.         c = call
  15.     d = drop
  16.     5 players are in the game
  17.  
  18.     Example input would be:
  19.     5cccc
  20.     5cc10cc
  21.         100cc5cc
  22.  
  23.     My problem with the program, is that the only time the program is 
  24. 100% correct is when I have a single digit number followed by c's or d's.
  25. Anything else will give a slightly higher answer than I need.  Here is 
  26. the function.
  27.  
  28. ******    If anybody can help me with this code, I'd be in their debt!
  29.  
  30. Thanks,
  31. Paul Haley
  32.  
  33. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  34.  
  35. void array_check(int i, char storage[])
  36. {
  37.    int pot=0, j=0, temp=0, old_call_value=0, raise=0;
  38.    int call_value=0, num_plays=0, prev=0, c=0, count=0;
  39.    char temp2;
  40.  
  41.    for (j=0; j<i; ++j)      
  42.    {
  43.       if (isdigit(storage[j]) != 0)  
  44.       {                
  45.         if ( prev==1)  /* prev means there was a previous digit */  
  46.           {           
  47.            temp2=storage[j];
  48.            c=atoi(&temp2);
  49.            temp=temp*10+c;
  50.            prev=1;
  51.          }
  52.          else 
  53.          {
  54.        temp2=storage[j];
  55.            temp=atoi(&temp2);
  56.            prev=1;
  57.          }
  58.          old_call_value=call_value;
  59.          puts("call_value=temp"); 
  60.          call_value+=temp;
  61.  
  62.       }  
  63.       if (storage[j]=='c')    /* begin 'c' check */
  64.       {
  65.          printf("storage[%d] = 'c'\n", j);
  66.      old_call_value=0;  
  67.      prev=0; 
  68.       }                       /* end 'c' check */
  69.       if (storage[j]=='d')  /* begin 'd' check */
  70.       {
  71.          old_call_value=0;
  72.      prev=0;
  73.          puts("storage[j] = d and prev is set to 0");
  74.       }                     /* end 'd' check */
  75.       else
  76.     pot+=(call_value-old_call_value);  
  77.   }  
  78.    end_game(pot);
  79. }
  80.  
  81.  
  82.  
  83.